package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Employeeleave;
import com.restaurant.service.EmployeeleaveService;

public class EmployeeleaveServiceImpl implements EmployeeleaveService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeleave addOrModify( Employeeleave objEmployeeleave ) {
       return ( Employeeleave ) hibernateTemplate.merge( objEmployeeleave );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeleave deleteRecord( Employeeleave objEmployeeleave ) {
       hibernateTemplate.delete( objEmployeeleave );
       return objEmployeeleave;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeleave modifyRecord( Employeeleave objEmployeeleave ) {
       return ( Employeeleave ) hibernateTemplate.merge( objEmployeeleave );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Employeeleave> loadAll() {
       return (List<Employeeleave>)hibernateTemplate.findByNamedQuery( "Employeeleave.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeleave loadByPrimaryKey( Long primaryKey ) {
       return (Employeeleave) hibernateTemplate.get( Employeeleave.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeleave deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Employeeleave> loadByHql(String query) {
       return ( List<Employeeleave> ) hibernateTemplate.find( query );
   }
}